package com.zegome.game.gomestory.main.scene.play.board;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.zegome.game.entity.sprite.BaseSprite;

public class LineConnect extends BaseSprite {

	public float wiLine=5;	
	private Line[] lines;
	private int index;
	Board board;
	
	public LineConnect(Board board, float pX, float pY) {
		super(pX, pY);
		this.board = board;
		lines = new Line[3];
		lines[0] = new Line();
		lines[1] = new Line();
		lines[2] = new Line();
	}
	
	public void resetLine() {
		index = 0;
		wiLine = (5);
	}

	public void add(int type, float x1, float y1, float x2, float y2) {
		lines[index].set(type, x1, y1, x2, y2);
		index++;
	}
	
	@Override
	public void onDraw(final SpriteBatch pSpriteBatch, final float pAlpha) {
		if(isVisible == false)
			return;
		if (index != 0) {
			for (int i = 0; i < index; i++) {
				if (lines[i].type == 0)
					pSpriteBatch.draw(board.screen.ctr.a.horRegion,
							lines[i].x1 ,
							lines[i].y1-wiLine/2,
							(lines[i].x2 - lines[i].x1),
							(wiLine));
				else {
					pSpriteBatch.draw(board.screen.ctr.a.verRegion,
							lines[i].x1-wiLine/2,
							lines[i].y1							,
							(wiLine),
							(lines[i].y2 - lines[i].y1));
				}
			}
		}
	}

}

class Line{
	
	int type;
	// 0: hor
	// 1: ver
	float x1, y1, x2, y2;
	
	public void set(int type, float x1, float y1, float x2, float y2) {
		this.type = type;
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
}
